let Func = {};

Func.scoreShow = (val) => {
    if(!val) {
      return '0';
    }
    if(String(val).indexOf('.')  == -1 || String(val).split(".")[1].length <= 2) {
      //小数位数小于2的原样返回
      return String(val);
    }else {
      return Number(val.toFixed(2)) + '';
    }
};

Func.strShow = (val, length) => {
    if(val.length < length - 3) {
      return val;
    }else {
      return val.substring(0, length - 3) + "..."
    }
},

Func.Time = {};

Func.Time.dateFormat = (date, format) => {
    let year = date.getFullYear();  
    let month = String(date.getMonth() + 1).padStart(2, '0');  
    let day = String(date.getDate()).padStart(2, '0');  
    let hours = String(date.getHours()).padStart(2, '0');  
    let minutes = String(date.getMinutes()).padStart(2, '0');  
    let seconds = String(date.getSeconds()).padStart(2, '0');  
  
    // 使用正则表达式替换格式字符串中的占位符  
    let formattedDate = format.replace('yyyy', year)  
        .replace('MM', month)  
        .replace('dd', day)  
        .replace('HH', hours)  
        .replace('mm', minutes)  
        .replace('ss', seconds);  

    return formattedDate; 
};

Func.Time.timestampFormat = (timestamp, format) => {
    let date = new Date();
    date.setTime(timestamp);
    return Func.Time.dateFormat(date, format);
};

export default Func;